package cn.edu.njust.alg.leetcode;

import cn.edu.njust.alg.ArrayUtils;

public class Leetcode_137_singleNumberII {

	/*
	 * Given an array of integers, every element appears twice except for one.
	 * Find that single one.
	 * 
	 * Note: Your algorithm should have a linear runtime complexity. Could you
	 * implement it without using extra memory?
	 */
	public int singleNumber(int[] nums) {
		int res = 0;
		int[] rs = new int[32];
		for (int num : nums) {
			int t = num;
			for (int i = 0; i < 32; i++) {
				rs[i] += t & 1;
				rs[i] %= 3;
				t = t >> 1;
			}
		}
		ArrayUtils.printArray(rs);
		for (int i = 0; i < rs.length; i++) {
			res += rs[i] << i;
		}
		return res;
	}

	public int singleNumber_1(int[] nums) {
		int ones = 0;
		
		for(int i=0;i<nums.length;i++){
			
		}
		
		return ones;
	}

	public static void main(String[] args) {
		int[] a = { 2, 2, 3, 5, 7, 7, 5, 2, 5, 7 };
		System.out.println(new Leetcode_137_singleNumberII().singleNumber(a));
	}

}
